package edu.upc.fib.lamsandroid.server.api.response;

import java.util.ArrayList;
import java.util.List;

public abstract class Response<M> {

    //TODO: enum
    public static final int OPERATION_SUCCESSFUL = 0;
    public static final int INVALID_SESSION_STATE = 1;

    private int code;

    private List<M> payload;

    protected Response() {
        setCode(OPERATION_SUCCESSFUL);
    }

    public Response(int code) {
        setCode(code);
    }

    public Response(M payload) {
        ArrayList<M> payloadList = new ArrayList<M>(1);
        payloadList.add(payload);

        setCode(OPERATION_SUCCESSFUL);
        setPayload(payloadList);
    }

    public Response(List<M> payload) {

        setCode(OPERATION_SUCCESSFUL);
        setPayload(payload);
    }

    public Response(int code, M payload) {
        ArrayList<M> payloadList = new ArrayList<M>(1);
        payloadList.add(payload);

        setCode(code);
        setPayload(payloadList);
    }

    public Response(int code, List<M> payload) {
        setCode(code);
        setPayload(payload);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public List<M> getPayload() {
        return payload;
    }

    public void setPayload(List<M> payload) {
        this.payload = payload;
    }
}
